#include <iostream>
#include <stack>
using namespace std;

int st[100000];
int top;

int longestValidParentheses(string s) {
    int ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i] == '(') st[top++] = i;
        else if(s[i] == ')' && top != 0){
            ans = max(ans, i-st[top-1] + 1);
            --top;
        }
    }
    return ans;
}

int main() {
    string s = "())";
    int ans = longestValidParentheses(s);
    cout << ans << endl;
}